<?php
namespace app\index\controller;

use app\common\controller\Base;
use app\index\model\DCharacter;
use app\index\model\LRegister;
use app\index\model\SkyladderChar;

/**
 * 游戏用户类
 */
class User extends Base
{
    /**
     * 控制器初始化
     * @return   void
     */
    public function _initialize()
    {
        //基类授权
        //
        parent::_initialize();
    }
    /**
     * 基本信息查询
     */
    public function queryBasicInfo()
    {

        try {

            //服务器ID
            //$sid = array_key_exists("sid",$_REQUEST) ? $_REQUEST['sid']:null;

            //角色ID昵称
            $id       = array_key_exists("id", $_REQUEST) ? $_REQUEST['id'] : null;
            $nickname = array_key_exists("nickname", $_REQUEST) ? $_REQUEST['nickname'] : null;

            $rtn = array();

            //==============
            //1.角色信息查询
            //==============
            $res = DCharacter::where("(`id`='{$id}' OR `nickname`='{$nickname}')")
                ->field("`id`,`nickname`,`level`,`exp`,`money`,`coin`,`energy`,`lastonlogintime`")
                ->find();
            if ($res) {
                $res = $res->getData();
                $rtn = array_merge($rtn, $res);
            }
            //===========
            //2.天梯数据
            /*===========
            $res = SkyladderChar::where("`characterid`='{$id}'")
                ->field("`level` as sky_level,`star` as sky_star,`score` as sky_score,`kingtimes` as sky_image")
                ->find();
            if ($res) {
                $res = $res->getData();
                $rtn = array_merge($rtn, $res);
            }*/
            //===========
            //3.注册数据
            //===========
            $res = LRegister::where("`characterid`='{$id}'")
                ->field("`chanel`,`createtime`")
                ->find();
            if ($res) {
                $res = $res->getData();
                $rtn = array_merge($rtn, $res);
            }
            /*==========
            //4.任务表
            //==========
            $res = Task::where("`characterid`='{$id}'")
            ->field("`goal_point`")
            ->find();
            if ($res) {
            $res = $res->getData();
            $rtn = array_merge($rtn, $res);
            }*/

            //查询数据
            $output = array('success' => $rtn ? true : false, 'msg' => $rtn ? "查询成功" : "没有找到玩家信息", 'data' => $rtn);

            //根据请求返回信息
            _callback($output);

        } catch (\Exception $e) {

            $output = array('success' => false, 'msg' => $e->getMessage());

            _callback($output);
        }
    }
}
